package com.bupt.ilink.http;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R implements Serializable {

    private static final long serialVersionUID = 7988823970938566753L;

    private Integer code;

    private String message;

    private Object data;

    public static R from(State state, Object data){
        R r = from(state);
        r.data = data;
        return r;
    }

    public static R from(State state){
        R r = new R();
        r.code = state.code();
        r.message = state.message();
        return r;
    }

    public static R ok() {
        return from(RState.SUCCESS);
    }

    public static R ok(Object data) {
        return from(RState.SUCCESS, data);
    }

    public static R failure() {
        return from(RState.FAILURE);
    }

    public static R failure(Object data) {
        return from(RState.FAILURE, data);
    }
}
